<template>
	<view>
		<u-navbar height="50" back-icon-color="#333" title="修改登录密码" title-color="#333" title-size="36"></u-navbar>
		<view class="itemView">
			<view class="inputView">
				<input placeholder="请输入原登录密码" placeholder-style="color:#999;letter-spacing: 2px;" v-model="oldPassword"
					:password="isHide" />
			</view>
			<view class="inputView">
				<input placeholder="请输入新密码" placeholder-style="color:#999;letter-spacing: 2px;" v-model="password"
					:password="isHide2" />
			</view>
			<view class="inputView">
				<input placeholder="请再次确认新密码" placeholder-style="color:#999;letter-spacing: 2px;" v-model="password2"
					:password="isHide2" />
			</view>
		</view>
		<view class="nextTitle" @click="onSave">确认修改</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isHide: true,
				isHide2: true,
				oldPassword: '',
				password: '',
				password2: ''
			}
		},
		methods: {
			onShowPwd(isHide) {
				this.isHide = !isHide;
			},
			onShowPwd2(isHide) {
				this.isHide2 = !isHide;
			},
			onSave() {
				let self = this
				if (this.$utils.isEmpty(this.oldPassword)) {
					this.$utils.tips('请输入原密码');
					return
				}
				if (this.$utils.isEmpty(this.password)) {
					this.$utils.tips('请输入新密码');
					return
				}
				if (this.$utils.isEmpty(this.password2)) {
					this.$utils.tips('请再次确认新密码');
					return
				}
				this.$user.passwordChange({
					old_password: this.oldPassword,
					password: this.password,
					password_confirmation: this.password2
				}, true).then(res => {
					self.$utils.tips('修改成功！');
					uni.setStorageSync('isLogin', false);
					uni.setStorageSync('access_token', '');
					uni.removeStorageSync('access_token');
					setTimeout(function() {
						uni.redirectTo({
							url: '/pages/login/login'
						});
					}, 500);
				});
			}
		}
	}
</script>

<style lang="scss">
	@import url('edit-login-pwd.css');

	page {
		background: #FFF;
	}
</style>
